/**
 * 
 */
package dao;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import common.Constant;
import model.ThanhVienModel;
import util.DataUtil;

/**
 * @author ThienVD
 *
 */
public class ThanhVienDAO {
	public static ThanhVienModel timThanhVien(String username, String password) {
		ThanhVienModel thanhVienModel = new ThanhVienModel();
		try {
			PreparedStatement preparedStatement = DataUtil
					.getConnection()
					.prepareStatement(
							Constant.SQL_RES
									.getString("sql.getThanhVienByTenDangNhapAndMatKhau"));
			preparedStatement.setString(1, username);
			preparedStatement.setString(2, password);
			ResultSet rs = preparedStatement.executeQuery();
			if (rs.next()) {
				thanhVienModel.setMaThanhVien(rs.getString("MaThanhVien"));
				thanhVienModel.setTenDangNhap(rs.getString("TenDangNhap"));
				thanhVienModel.setMatKhau(rs.getString("MatKhau"));
				if(rs.getString("MaThanhVien").equals("SV00")) {
					thanhVienModel.setMaThanhVien("QUAN TRI");
				}
				else {
					thanhVienModel.setMaThanhVien("SINH VIEN");// lay ma bo phan cua thanh vien
				}
				return thanhVienModel;
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}
}

